﻿using DailyApp.WPF.DTOs;
using DailyApp.WPF.Service;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DailyApp.WPF.ViewModels.DialogViewModels
{
    class ModifyWaitUCViewModel : BindableBase, IDialogHostAware
    {
        public DelegateCommand SaveCommand { get; set; }
        public DelegateCommand CancelCommand { get; set; }

        //DTO属性-单项绑定用于数据回传
        public WaitTodoInfoDTO WaitTodoInfoDTO { get; set; } = new WaitTodoInfoDTO();//防止没有Key时候空引用

        public void OnDialogOpening(IDialogParameters parameters)
        {
            WaitTodoInfoDTO = parameters.GetValue<WaitTodoInfoDTO>("OldWait");

            CancelCommand = new DelegateCommand(CancelFunc);
            SaveCommand = new DelegateCommand(SaveFunc);
        }

        #region 具体方法实现

        /// <summary>
        /// 取消
        /// </summary>
        private void CancelFunc()
        {
            if (DialogHost.IsDialogOpen("RootDialog"))
            {
                DialogHost.Close("RootDialog", new DialogResult(ButtonResult.OK));
            }
        }


        /// <summary>
        /// 确定修改
        /// </summary>
        private void SaveFunc()
        {
            if (DialogHost.IsDialogOpen("RootDialog"))
            {
                var param = new DialogParameters();
                param.Add("NewWait", WaitTodoInfoDTO);

                DialogHost.Close("RootDialog", new DialogResult(ButtonResult.OK, param));//传递回修改后的新数据
            }
        }

        #endregion
    }
}
